from datetime import datetime
from typing import Optional

from pydantic import BaseModel, validator


class GpsTelemetry(BaseModel):
    status: bool = False
    timestamp: datetime = datetime.utcnow()
    latitude: float = 0.0
    north_south: str = 'N'
    longitude: float = 0.0
    east_west: str = 'E'
    raw_message: str = ''
    last_capture_time: Optional[datetime] = None
    last_bs_capture_time: Optional[datetime] = None

    @validator('latitude', pre=True, always=True)
    def validate_latitude(cls, v):
        if isinstance(v, (int, float)):
            return v
        return 0.0

    @validator('longitude', pre=True, always=True)
    def validate_longitude(cls, v):
        if isinstance(v, (int, float)):
            return v
        return 0.0
